var path;
var htmlTable = "";
var htmlTable4 = "";
var check = '';
var sum = 0;
var lineNum1 = 0;//记录查询结果条数
var lineNum2 = 0;
var lineNum3 = 0;
var lineNum4 = 0;
var maxDiv1 = 0; //页签扩展标识
var maxDiv2 = 0;
var maxDiv3 = 0;
var maxDiv4 = 0;
$(document).ready(function() {
	path=$("#commonPath").attr("value");
	$("#edit").click(function() {
	});
	
	//汇款明细产看点击事件
	$("div[name='showName']").each(function(){	
		var btn = $(this);
		$(this).click(function(){
			if($("#"+btn.attr("id")+"div").css("display")!="block"){
				$("#"+btn.attr("id")+"div").animate({ height: 'show', opacity: 'show' }, 'slow');
			}else{
				$("#"+btn.attr("id")+"div").animate({ height: 'hide', opacity: 'hide' }, 'slow');
			}
		});
		
	});
	
	$("input[name='checkName_single']").click(function(){
		$(this).each(function(){
			if(this.checked){
				//$("input[name='checkName_single']").not($(this)).removeAttr("checked");
				csChaNot();
				$("#amoSumSpan").html("0.00");
				sum = 0.00;
		    }else{
		    	csChaNot();
				$("#amoSumSpan").html("0.00");
				sum = 0.00;
		    }
		});
	});
	
	var remiIdArrayIds = $("#remiId").val();
	if(remiIdArrayIds == "" || remiIdArrayIds == null){
		$("#remitDialog").hide();
	}
	
	//查询后默认显示事件    ----*****-----
	var ck = $("input[name='checkName_single']");
	
	var chaNotNo = $("input[name='chaNotNo']").val();
	if(ck.length > 0 && chaNotNo != "" && null != chaNotNo && chaNotNo !="*"){
		$(ck).each(function(){
			if($(this).attr('index')==1){
				$(this).attr("checked",true);
			}
			csChaNot(chaNotNo);
		});
	}
   
    var chaNotNoEnd = $("input[name='chaNotNoEnd']").val();
	if(ck.length > 0 && chaNotNoEnd != "" && null != chaNotNoEnd && chaNotNoEnd !="*"){
		$(ck).each(function(){
			if($(this).attr('index')==1){
				$(this).attr("checked",true);
			}
			csChaNot(chaNotNoEnd);
		});
	 }
    
    
	/**
	 * 以下代码为给四个table加上默认行显示
	 */
	var content1 = $("#table1 tr:first-child").html();
    content1 = "<thead><tr>" + content1 + "</tr></thead>";
	var content2 = $("#table2 tr:first-child").html();
    content2 = "<thead><tr>" + content2 + "</tr></thead>";
	var content3 = $("#table3 tr:first-child").html();
    content3 = "<thead><tr>" + content3 + "</tr></thead>";
	var content4 = $("#table4 tr:first-child").html();
    content4 = "<thead><tr>" + content4 + "</tr></thead>";
    
    htmlTable += "<tr><td width='20px'><input type='checkbox' disabled='disabled'/></td>" + 
                 "<td>&nbsp;</td><td>&nbsp;</td>" + 
			     "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    
	$('#table1').html(content1 + htmlTable + htmlTable + htmlTable);
	$('#table2').html(content2 + htmlTable + htmlTable + htmlTable);
	$('#table3').html(content3 + htmlTable + htmlTable + htmlTable);
	
	htmlTable4 += "<tr><td width='20px'><input type='checkbox' disabled='disabled'/></td>" + 
				     "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" + 
				     "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
	$('#table4').html(content4 + htmlTable4 + htmlTable4 + htmlTable4);
	// END----四个table默认行添加完毕
	
	$('#table1').sorttable();
	$('#table2').sorttable();
	$('#table3').sorttable();
	$('#table4').sorttable();
	
	//隔行换色
	var num = 0;
	$("#table1 tr").each(function(){
		num++;
		if(num%2 != 0){
			$(this).addClass("odd");
		}
	});
	$("#table2 tr").each(function(){
		num++;
		if(num%2 != 0){
			$(this).addClass("odd");
		}
	});
	$("#table3 tr").each(function(){
		num++;
		if(num%2 != 0){
			$(this).addClass("odd");
		}
	});
	$("#table4 tr").each(function(){
		num++;
		if(num%2 != 0){
			$(this).addClass("odd");
		}
	});
	//防止改变页面布局 谷歌 ie 8 9 会出现 将固定表头绝对定位
	window.setInterval(function pos(){
		$("div[name='overHeadDiv']").each(function(){
		    $(this).first().find("table").css("position","absolute");
		})
	},50);
	
});

// 是否选择数据,name接收参数为checkbox的name
function checks(name) {
	var id = document.getElementsByName(name);
	for (var i = 0; i < id.length; i++) {
		if (id[i].checked) {
			return true;
		}
	}
	return false;
}

// 选中记录
function csChaNot(obj) {
	openWaitWin("数据查询中...请稍候");
	var ids = [];
	$("input[name='checkName_single']:checked").each(function(){
		ids.push($(this).val());
	});
	var remiIds = $("#remiId").val();//获取汇款单ID串
	if(obj == undefined){
		obj = "";
	}
	var payTag = $("#payTag").val();//是否代缴
	if(payTag==undefined){
		payTag = "";
	}
	var chaNotNo = $("input[name='chaNotNo']").val();
	if(null != chaNotNo && chaNotNo !=""){
		obj = chaNotNo;
	}
		$.ajax({
					type : "POST",
					timeout : 2000000,
					dataType : 'json',
					url : "fmChaNotAction.action",
					data : "ids=" + ids.join(",") + "&chaNotNo=" + obj + "&remiIds=" + remiIds + "&formCsChaNot.payTag="+payTag,
					success : function(result) {
						if(result.exception!=undefined){
							closeWaitWin();
							alertShow("未返回数据，请稍后点击重试");
							return;
						}
						if(null!=result && ""!=result){
							$("#table1 tr:[name='table1_tr']").remove();
							$("#table2 tr:[name='table2_tr']").remove();
							$("#table3 tr:[name='table3_tr']").remove();
							$("#table4 tr:[name='table4_tr']").remove();
                            var htm1 = "";
                            var htm2 = "";
                            var htm3 = "";
                            var htm4 = "";
                            var flag1;
                            var flag2;
                            var flag3;
                            var flag4;
                            if(null!=result.chaList && ""!=result.chaList) {//应收
                            	flag1 = 1;
                            	lineNum1 = result.chaList.length;
                            	if(lineNum1==undefined){
                            		lineNum1 = 0;
                            	}
                                $.each(result.chaList,function(index,value){
                                	var chaTag = "";
                                	switch(value.chaTag){
                                		case 1:
										chaTag = "未交";
										break;
										case 2:
										chaTag = "已交";
										break;
										case 3:
										chaTag = "欠费";
										break;
                                	}
                                	var invTag = "";
                                	switch(value.invTag){
                                		case 1:
                                		invTag = "未打票";
										break;
										case 2:
										invTag = "打票";
										break;
										case 3:
										invTag = "借票";
										break;
										case 4:
										invTag = "换票";
										break;
                                	}
                             
                                   if(value.chaTag == 2){
                                       htm1+="<tr name='table1_tr' id='fmChaNot"+index+"' class='tagComplete' ondblclick='searchDet("+value.chaNotId+",1)'>";
                                    }else{
                                       htm1+="<tr name='table1_tr' id='fmChaNot"+index+"' ondblclick='searchDet("+value.chaNotId+",1)'>";
                                   }
                            
                                   htm1 += "<td width='20px' class='fxk'>"+
                                    "<input id='check' claTag ='1' invTag='" + value.invTag + "' chaTag='" + value.chaTag 
                                    + "' name='checkName_two' type='checkbox' onclick='amoSum(this)' value='"+value.chaNotId
                                    + "' amo='" + value.orderFnncAmo + "'/>"+
                                    "</td>"+
                                    "<td id='busiYm"+index+"'>"+value.busiYm+"</td>"+
                                    "<td id='chaNotNo"+index+"'>"+value.chaNotNo+"</td>"+
                                    "<td align='right' name='orderFnncAmo' id='orderFnncAmo"+index+"'>"+formatNumber(value.orderFnncAmo)+"</td>"+
                                    "<td id='invTag"+index+"'>"+invTag+"</td>"+
                                    "<td id='chaTag"+index+"'>"+chaTag+"</td>"+
                                    "<td id='busiCustCode"+index+"'>"+value.busiCustCode+"</td>"+
                                    "<td id='busiCustName"+index+"'>"+value.busiCustName+"</td>"+
                                    "</tr>";
                                });

                            }else{
                            	lineNum1 = 0;
                            }
                            if(null!=result.payList && ""!=result.payList) {//欠费
                            	flag2=2;
                            	lineNum2 = result.payList.length;
                            	if(lineNum2==undefined){
                            		lineNum2 = 0;
                            	}
                            	$.each(result.payList,function(index,value){
                            		var chaTag = "";
                                	switch(value.chaTag){
                                		case 1:
										chaTag = "未交";
										break;
										case 2:
										chaTag = "已交";
										break;
										case 3:
										chaTag = "欠费";
										break;
                                	}
                                	var invTag = "";
                                	switch(value.invTag){
                                		case 1:
                                		invTag = "未打票";
										break;
										case 2:
										invTag = "打票";
										break;
										case 3:
										invTag = "借票";
										break;
										case 4:
										invTag = "换票";
										break;
                                	}
                                	
                                   if(value.chaTag == 2){
                                      	htm2+="<tr name='table2_tr' id='fmChaNot"+index+"' class='tagComplete' ondblclick='searchDet("+value.chaNotId+",2)'>";
                                    }else{
                                     	htm2+="<tr name='table2_tr' id='fmChaNot"+index+"' ondblclick='searchDet("+value.chaNotId+",2)'>";
                                   }
                            
                                    htm2+="<td width='28' class='fxk'>"+
                                    "<input id='check'  claTag ='2' invTag='" + value.invTag + "' chaTag='" + value.chaTag 
                                    + "'  name='checkName_two' type='checkbox' onclick='amoSum(this)' value='"+value.chaNotId
                                    + "' amo='" + value.orderFnncAmo + "'/>"+
                                    "</td>"+
                                    "<td id='busiYm"+index+"'>"+value.busiYm+"</td>"+
                                    "<td id='chaNotNo"+index+"'>"+value.chaNotNo+"</td>"+
                                    "<td align='right' name='orderFnncAmo' id='orderFnncAmo"+index+"'>"+formatNumber(value.orderFnncAmo)+"</td>"+
                                    "<td id='invTag"+index+"'>"+invTag+"</td>"+
                                    "<td id='chaTag"+index+"'>"+chaTag+"</td>"+
                                    "<td id='busiCustCode"+index+"'>"+value.busiCustCode+"</td>"+
                                    "<td id='busiCustName"+index+"'>"+value.busiCustName+"</td>"+
                                    "</tr>";
                                });
                            }else{
                            	lineNum2 = 0;
                            }
                            if(null!=result.funList && ""!=result.funList) {//公积金
                            	flag3=3;
                            	lineNum3 = result.funList.length;
                            	if(lineNum3==undefined){
                            		lineNum3 = 0;
                            	}
                            	$.each(result.funList,function(index,value){
                            		var chaTag = "";
                                	switch(value.chaTag){
                                		case 1:
										chaTag = "未交";
										break;
										case 2:
										chaTag = "已交";
										break;
										case 3:
										chaTag = "欠费";
										break;
                                	}
                                	var invTag = "";
                                	switch(value.invTag){
                                		case 1:
                                		invTag = "未打票";
										break;
										case 2:
										invTag = "打票";
										break;
										case 3:
										invTag = "借票";
										break;
										case 4:
										invTag = "换票";
										break;
                                	}
                                	if(value.chaTag == 2){
                                	   htm3+="<tr name='table3_tr' id='fmChaNot"+index+"' class='tagComplete' ondblclick='searchDet("+value.chaNotId+",3)'>";
                                	}else{
                                       htm3+="<tr name='table3_tr' id='fmChaNot"+index+"' ondblclick='searchDet("+value.chaNotId+",3)'>";
                                	}
                            
                                     htm3+="<td width='28' class='fxk'>"+
                                    "<input id='check' claTag ='3' invTag='" + value.invTag + "' chaTag='" + value.chaTag 
                                    + "' name='checkName_two' type='checkbox' onclick='amoSum(this)' value='"+value.chaNotId
                                    + "' amo='" + value.orderFnncAmo + "'/>"+
                                    "</td>"+
                                    "<td id='busiYm"+index+"'>"+value.busiYm+"</td>"+
                                    "<td id='chaNotNo"+index+"'>"+value.chaNotNo+"</td>"+
                                    "<td align='right' name='orderFnncAmo' id='orderFnncAmo"+index+"'>"+formatNumber(value.orderFnncAmo)+"</td>"+
                                    "<td id='invTag"+index+"'>"+invTag+"</td>"+
                                    "<td id='chaTag"+index+"'>"+chaTag+"</td>"+
                                    "<td id='busiCustCode"+index+"'>"+value.busiCustCode+"</td>"+
                                    "<td id='busiCustName"+index+"'>"+value.busiCustName+"</td>"+
                                    "</tr>";
                                });
                            }else{
                            	lineNum3 = 0;
                            }
                            if(null!=result.accList && ""!=result.accList) {//账期
                            	flag4=4;
                            	lineNum4 = result.accList.length;
                            	if(lineNum4==undefined){
                            		lineNum4 = 0;
                            	}
                            	$.each(result.accList,function(index,value){
                            		var chaTag = "";
                                	switch(value.chaTag){
                                		case 1:
										chaTag = "未交";
										break;
										case 2:
										chaTag = "已交";
										break;
										case 3:
										chaTag = "欠费";
										break;
                                	}
                                	var invTag = "";
                                	switch(value.invTag){
                                		case 1:
                                		invTag = "未打票";
										break;
										case 2:
										invTag = "打票";
										break;
										case 3:
										invTag = "借票";
										break;
										case 4:
										invTag = "换票";
										break;
                                	}
                                	var accper = value.accPer;
                                	if(accper==null){
                                		accper = "";
                                	}
                                	
                                	if(value.chaTag == 2){
                                	    htm4+="<tr name='table4_tr' id='fmChaNot"+index+"' class='tagComplete' ondblclick='searchDet("+value.chaNotId+",4)'>";
                                	}else{
                                	   	htm4+="<tr name='table4_tr' id='fmChaNot"+index+"' ondblclick='searchDet("+value.chaNotId+",4)'>";
                                	}
                       
                                    htm4+="<td width='28' class='fxk'>"+
                                    "<input id='check' claTag ='4' invTag='" + value.invTag + "' chaTag='" + value.chaTag 
                                    + "' name='checkName_two' type='checkbox' onclick='amoSum(this)' value='"+value.chaNotId
                                    + "' amo='" + value.orderFnncAmo + "'/>"+
                                    "</td>"+
                                    "<td id='busiYm"+index+"'>"+value.busiYm+"</td>"+
                                    "<td id='chaNotNo"+index+"'>"+value.chaNotNo+"</td>"+
                                    "<td align='right' name='orderFnncAmo' id='orderFnncAmo"+index+"'>"+formatNumber(value.orderFnncAmo)+"</td>"+
                                    "<td id='invTag"+index+"'>"+invTag+"</td>"+
                                    "<td id='chaTag"+index+"'>"+chaTag+"</td>"+
                                //  "<td id='accPer"+index+"'>"+accper+"</td>"+
                                    "<td id='lastChaDate"+index+"'>"+value.lastChaDate.substr(0,10)+"</td>"+
                                    "<td id='busiCustCode"+index+"'>"+value.busiCustCode+"</td>"+
                                    "<td id='busiCustName"+index+"'>"+value.busiCustName+"</td>"+
                                    "</tr>";
                                });
                            }else{
                            	lineNum4 = 0 ;
                            }

                            var content1=$("#table1 tr:first-child").html();
                            content1="<thead><tr>"+content1+"</tr></thead>";
                            if(flag1==1) {//应收
                            	var minDiv = content1 +　htm1;
                            	if(maxDiv1==1){
                            		if(lineNum1>=0&&lineNum1<10){
                            			for(var i=1 ;i<11-lineNum1;i++){
                            				minDiv = minDiv + htmlTable;
                            			}
                            			$('#table1').html(minDiv);
                            		}else{
                            			$('#table1').html(minDiv);
                            		}
                            	}else{
                            		if(lineNum1 == 1){
                            			$('#table1').html(content1+ htm1 + htmlTable + htmlTable);
                            		}else if(lineNum1 == 2){
                            			$('#table1').html(content1+ htm1 + htmlTable);
                            		}else{
                            			$('#table1').html(content1 + htm1);
                            		}
                            	}
                            }else{
                            	var minDiv = content1 + htm1;
                            	if(maxDiv1==1){
                            		if(lineNum1>=0&&lineNum1<10){
                            			for(var i=1 ;i<11-lineNum1;i++){
                            				minDiv = minDiv + htmlTable;
                            			}
                            			$('#table1').html(minDiv);
                            		}else{
                            			$('#table1').html(minDiv);
                            		}
                            	}else{
                            		$('#table1').html(content1+ htm1 + htmlTable + htmlTable + htmlTable);
                            	}
                            }
                            
                            var content2=$("#table2 tr:first-child").html();
                            content2="<thead><tr>"+content2+"</tr></thead>";
                            if(flag2==2) {//欠费
                            	var minDiv = content2 +　htm2;
                            	if(maxDiv2==1){
                            		if(lineNum2>=0&&lineNum2<10){
                            			for(var i=1 ;i<11-lineNum2;i++){
                            				minDiv = minDiv + htmlTable;
                            			}
                            			$('#table2').html(minDiv);
                            		}else{
                            			$('#table2').html(minDiv);
                            		}
                            	}else{
                            		if(lineNum2 == 1){
                            			$('#table2').html(content2 + htm2 + htmlTable + htmlTable);
                            		}else if(lineNum2 == 2){
                            			$('#table2').html(content2+ htm2 + htmlTable);
                            		}else{
                            			$('#table2').html(content2 + htm2);
                            		}
                            	}
                            }else{
                            	var minDiv = content2 + htm2;
                            	if(maxDiv2==1){
                            		if(lineNum2>=0&&lineNum2<10){
                            			for(var i=1 ;i<11-lineNum2;i++){
                            				minDiv = minDiv + htmlTable;
                            			}
                            			$('#table2').html(minDiv);
                            		}else{
                            			$('#table2').html(minDiv);
                            		}
                            	}else{
                            		$('#table2').html(content2+ htm2 + htmlTable + htmlTable + htmlTable);
                            	}
                            }
                            
                            var content3=$("#table3 tr:first-child").html();
                            content3="<thead><tr>"+content3+"</tr></thead>";
                            if(flag3==3) {//公积金
                            	var minDiv = content3 +　htm3;
                            	if(maxDiv3==1){
                            		if(lineNum3>=0&&lineNum3<10){
                            			for(var i=1 ;i<11-lineNum3;i++){
                            				minDiv = minDiv + htmlTable;
                            			}
                            			$('#table3').html(minDiv);
                            		}else{
                            			$('#table3').html(minDiv);
                            		}
                            	}else{
                            		if(lineNum3 == 1){
                            			$('#table3').html(content3 + htm3 + htmlTable + htmlTable);
                            		}else if(lineNum3 == 2){
                            			$('#table3').html(content3+ htm3 + htmlTable);
                            		}else{
                            			$('#table3').html(content3 + htm3);
                            		}
                            	}
                            }else{
                            	var minDiv = content3 + htm3;
                            	if(maxDiv3==1){
                            		if(lineNum3>=0&&lineNum3<10){
                            			for(var i=1 ;i<11-lineNum3;i++){
                            				minDiv = minDiv + htmlTable;
                            			}
                            			$('#table3').html(minDiv);
                            		}else{
                            			$('#table3').html(minDiv);
                            		}
                            	}else{
                            		$('#table3').html(content3+ htm3 + htmlTable + htmlTable + htmlTable);
                            	}
                            }
                            
                            var content4=$("#table4 tr:first-child").html();
                            content4="<thead><tr>"+content4+"</tr></thead>";
                            if(flag4==4) {//账期
                            	var minDiv = content4 +　htm4;
                            	if(maxDiv4==1){
                            		if(lineNum4>=0&&lineNum4<10){
                            			for(var i=1 ;i<11-lineNum4;i++){
                            				minDiv = minDiv + htmlTable4;
                            			}
                            			$('#table4').html(minDiv);
                            		}else{
                            			$('#table4').html(minDiv);
                            		}
                            	}else{
                            		if(lineNum4 == 1){
                            			$('#table4').html(content4 + htm4 + htmlTable4 + htmlTable4);
                            		}else if(lineNum4 == 2){
                            			$('#table4').html(content4 + htm4 + htmlTable4);
                            		}else{
                            			$('#table4').html(content4 + htm4);
                            		}
                            	}
                            }else{
                            	var minDiv = content4 + htm4;
                            	if(maxDiv4==1){
                            		if(lineNum4>=0&&lineNum4<10){
                            			for(var i=1 ;i<11-lineNum4;i++){
                            				minDiv = minDiv + htmlTable4;
                            			}
                            			$('#table4').html(minDiv);
                            		}else{
                            			$('#table4').html(minDiv);
                            		}
                            	}else{
                            		$('#table4').html(content4+ htm4 + htmlTable4 + htmlTable4 + htmlTable4);
                            	}
                            }
                            //隔行换色
                        	var trNum1 = 0;
                        	$("#table1 tr").each(function(){
                        		trNum1++;
                        		if(trNum1%2 != 0 && $(this).attr('class')!='tagComplete'){
                        			 $(this).addClass("odd");
                        		}
                        	});
                        	var trNum2 = 0;
                        	$("#table2 tr").each(function(){
                        		trNum2++;
                        		if(trNum2%2 != 0 && $(this).attr('class')!='tagComplete'){
                        			$(this).addClass("odd");
                        		}
                        	});
                        	var trNum3 = 0;
                        	$("#table3 tr").each(function(){
                        		trNum3++;
                        		if(trNum3%2 != 0 && $(this).attr('class')!='tagComplete'){
                        			$(this).addClass("odd");
                        		}
                        	});
                        	var trNum4 = 0;
                        	$("#table4 tr").each(function(){
                        		trNum4++;
                        		if(trNum4%2 != 0 && $(this).attr('class')!='tagComplete'){
                        			$(this).addClass("odd");
                        		}
                        	});
                        	
                        	$('#table1').sorttable();
                        	$('#table2').sorttable();
                        	$('#table3').sorttable();
                        	$('#table4').sorttable();
                        	//TODO 添加固定表头
//                        	thisTableHeadOver($('#table1'), 1);
//                        	thisTableHeadOver($('#table2'), 2);
//                        	thisTableHeadOver($('#table3'), 3);
//                        	thisTableHeadOver($('#table4'), 4);
                        }else{
                        	alertShow("返回数据为空！");
                        }
					
						var ckF = $("input[name='checkName_two']");
	                    var chaNotNo = $("input[name='chaNotNo']").val();
	                    if(ckF.length > 0 && chaNotNo != "" && null != chaNotNo && chaNotNo !="*" ){
	                    	$(ckF).each(function(){
                             $(this).attr("checked",true);
                             amoSum(this);
		                });
	                    }else{
	                    	$("#checkNotNum").html("0");
	                    	$("#amoSumSpan").html("0.00");
	                    }
	                    $("#table1 thead tr th").first().find(":checkbox").attr("checked",false);
	                    $("#table2 thead tr th").first().find(":checkbox").attr("checked",false);
	                    $("#table3 thead tr th").first().find(":checkbox").attr("checked",false);
	                    $("#table4 thead tr th").first().find(":checkbox").attr("checked",false);
	            		$("#checkbox1").attr("checked",false);
	            		$("#checkbox2").attr("checked",false);
	            		$("#checkbox3").attr("checked",false);
	            		$("#checkbox4").attr("checked",false);
	                    //overHeadFun($("#table1,#table2,#table3,#table4"));
	                    closeWaitWin();
					},
					error : function(msg) {
						closeWaitWin();
						//alertShow(msg);
						alertShow("未返回数据，请稍后点击重试");
					}
				});
}

//TODO 金额汇总
function amoSum(obj) {
    sum = 0;
	var checkNotNum = 0;
	var ck = $("input[name='checkName_two']:checked");
	$(ck).each(function(){
		sum = accAdd(sum, $(this).attr("amo"));
		checkNotNum++;
	});
//	var amo = $(obj).parents("tr").find("td[name='orderFnncAmo']").html();
//	var changeAmo = amo.replace(/,/g,"");
//	if($(obj).attr("checked")){
//	    sum = accAdd(sum,changeAmo);
//	}else{
//	    sum = accSubtr(sum,changeAmo);
//	}
	var newSum = parseFloat(sum).toFixed(2);
	$("#amoSumSpan").html(formatNumber(newSum));
	$("#checkNotNum").html(checkNotNum);
	$("#openSumShow").val(formatNumber(newSum));
	$("#openSumId").val(sum);
	//计算汇款单余额
	var remitAmo = $("#remiAmo").val();
	var remitBalance = accSubtr(remitAmo,sum);//remitAmo - sum;
	if(remitBalance > 0){
		$("#remitBalance").val(remitBalance);
	}else{
		$("#remitBalance").val("0.00");
	}
}

// 发票合计汇总
function total(num) {
	var ck = $("#table" + num + " tbody").find("input[name='checkName_two']:checked");
//	var ck = $("input[name='checkName_two']:checked");
	if(ck.length != 1){
		alertShow("请选择一条相关类型的通知单信息！");
	}else{
		var id = ck.val();
		if (id == undefined) {
			alertShow("请选择通知单记录！");
		} else {
			var url = getBasePath() + "/fm/invTotalAction.action?id="+id;
			$("#invFrame").attr("src",url);
			openDialog('shadowShowInv','dialogShowInv');
		}
	}
}

// 查看个人明细
function searchDet(chaNotId,num) {
	if(undefined !=chaNotId && null != chaNotId && "" != chaNotId){
		document.getElementById("detFrame").src = getBasePath() + "/cs/fmGetDetListByChaNotId.action?chaNotId="+chaNotId;
		openDialog('shadowShowDet','dialogShowDet');
	}else{
		var ck = $("#table" + num + " tbody").find("input[name='checkName_two']:checked");
		if(ck.length != 1){
			alertShow("请选择一条相关类型的通知单信息！");
		}else{
			var id = ck.val();
			if (id == undefined) {
				alertShow("请选择要查看个人明细的通知单记录");
			} else {
				document.getElementById("detFrame").src = getBasePath() + "/cs/fmGetDetListByChaNotId.action?chaNotId="+id;
				openDialog('shadowShowDet','dialogShowDet');
			}
		}
	}
}

function selectCheck(){
	var depId = $("#depId").val();
	var custNoId = $("#custNoId").val();
	var chaNotNoId = $("#chaNotNoId").val();
	var repId = $("#repId").val();
	var custNameId = $("#custNameId").val();
	if("" == depId && "" == custNoId && "*" == chaNotNoId && "" == repId && "" == custNameId){
		openDialog("shadow","DialogMsgOne");
	}else{
		$("#searchCsChaNotForms").submit();
	}
}
//以下两个方法是为了让主题的复选框全部选中后才执行csChaNot()方法二写的延迟加载方法，不可少
function toCheckAll(){
	setTimeout("toSelect()",300);
}

function toSelect(){
	var ck = $("input[name='checkName_single']:checked");
	setTimeout("csChaNot()",300);
}

//下半部分四个区域的全选事件
function toChackAll(id){
	var new2= $("#table"+id+" thead tr th").first().find(":checkbox");
	var ckAll= $("#table"+id+" thead tr:first-child").find(":checkbox");
	if(ckAll.attr("checked")){
		$("#table"+id+" tr td").find("input[name='checkName_two']").each(function(){
			if($(this).attr("checked")){
	//			$(this).attr("checked",false);
	//			amoSum(this);
			}else{
				$(this).attr("checked",true);
				amoSum(this);
			}
		});
	}else{
		$("#table"+id+" tr td").find("input[name='checkName_two']").each(function(){
			if($(this).attr("checked")){
				$(this).attr("checked",false);
				amoSum(this);
			}else{
				$(this).attr("checked",false);
//				amoSum(this);
			}
		});
   }
}

//打印事件
function toPrint(){
    openWaitWin('请等待');
	var path = getBasePath();
	//获取汇款单信息以判断
	var ids = $("#mFrame")[0].contentWindow.$("#ids").val();//通知单ID串
	if(undefined != ids){
		var remiAmo = $("#remiAmo").val();//汇款单金额
		var openSum = $("#openSumId").val();//通知单总金额
		//在汇款单打票的时候先判断汇款单金额与通知单总金额的大小
		var notRemiSum = accSubtr(parseFloat(remiAmo).toFixed(2),parseFloat(openSum).toFixed(2));
		if(remiAmo != null && remiAmo != "" && remiAmo > 0 && notRemiSum < 0){
			alertShow("提示：汇款单金额小于收费通知单总金额，不能进行打票！");
		}else{
			var chaNotItemList;//封装通知单发票汇总信息
			$.post(path + "/fm/selectChaNotTotalByIds.action", {"ids":ids}, function(result){
				if(result.exception!=undefined){
				    closeWaitWin();
					alertShow(result.exception.message);
				}else{
				    closeWaitWin();
					if(undefined != result.tempList){
						chaNotItemList = result.tempList;
					}
				}
			});
			
			//把需要打印的通知单信息封装到同一个list集合中
			var csChaNotList;//封装通知单信息
			var mainIds = [];
			$("input[name='checkName_single']:checked").each(function(){
				mainIds.push($(this).val());
			});
			$.post(path + "/fm/getInvChaList.action", {"ids":ids}, function(result){
				if(result.exception!=undefined){
				    closeWaitWin();
				    alertShow(result.exception.message);
				}else{
				    closeWaitWin();
					if(undefined != result.allChaNotList){
						csChaNotList = result.allChaNotList;
					}
				}
			});
			
			/****测试不连接本地vf库***/
			var conn = new ActiveXObject("ADODB.Connection");
			var strdsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\\SK;Exclusive=No;"
			conn.Open(strdsn);
			createInvMsg(conn , chaNotItemList , csChaNotList);
		}
	}else{
	    closeWaitWin();
		canclePri();
	}
}

//把通知单信息写入到税控机库中
function createInvMsg(conn , chaNotItemList , csChaNotList){
	if(undefined != chaNotItemList && undefined != csChaNotList){
		try {
			conn.BeginTrans();
			//通知单发票汇总信息的写入
			var sqlAll = "";
			if(undefined != chaNotItemList){
				$.each(chaNotItemList,function(index,value){
					var val = "'" + value.chaNotNo + "','(" + value.busiYm +")" + value.itemName + "'," 
							  + parseFloat(value.amo).toFixed(2) + ",'" + value.busiCustNo + "','0'";
//					var sql = "insert into cw_sk_detailstable values(" + val + ")";
//					conn.Execute(sql);
					sqlAll += "insert into cw_sk_detailstable values(" + val + ");";
				});
			}
			//通知单详细信息的写入
			if(undefined != csChaNotList){
				$.each(csChaNotList,function(index,value){
					var val = "'','" + value.chaNotNo + "','" + value.invUnitName + "','0','" 
							  + value.busiCustCode + "','0','"
							  + value.chaNotNo + "-" + value.orgCode + "',0";
//					var sql = "insert into cw_sk_maintable values(" + val + ")";
//					conn.Execute(sql);
					sqlAll += "insert into cw_sk_maintable values(" + val + ");";
				});
			}
			var connAll = conn.Execute(sqlAll);
			conn.CommitTrans();
			conn.Close();
			conn = null;
			connAll = null;
			//打印后，打印按钮失效
			$("#printBtn").attr("disabled",true);
			//完成按钮可以点击了
			$("#okBtn").attr("disabled",false);
			closeWaitWin();
		 } catch (e) {
		   closeWaitWin();
			alertShow(e.message);
			conn.RollbackTrans();
		}
	}
}

//完成打印后回写发票号
function writeBack() {
	var remiAmo = $("#remiAmo").val();//汇款单金额
	var openSum = $("#openSumId").val();//通知单总金额
	//在汇款单打票的时候先判断汇款单金额与通知单总金额的大小
	var notRemiSum = accSubtr(parseFloat(remiAmo).toFixed(2),parseFloat(remiAmo).toFixed(2));
	if(remiAmo != null && remiAmo != "" && remiAmo > 0 && notRemiSum < 0){
		alertShow("提示：汇款单总金额小于收费通知单总金额，不能进行打票！");
	}else{
		//把需要打印的通知单信息封装到同一个list集合中
		var csChaNotList;//封装通知单信息
		var mainIds = [];
		$("input[name='checkName_single']:checked").each(function(){
			mainIds.push($(this).val());
		});
		var ids = $("#mFrame")[0].contentWindow.$("#ids").val();//通知单ID串
		//获取需打印发票的通知单编号
		var chaNotNos = new Array();
		$.post(path + "/fm/getInvChaList.action", {"ids":ids}, function(result){
			if(result.exception!=undefined){
				closeWaitWin();
				alertShow(result.exception.message);
			}else{
				if(undefined != result.allChaNotList){
					csChaNotList = result.allChaNotList;
					$.each(csChaNotList,function(index,value){
						chaNotNos.push("'"+value.chaNotNo+"'");
					});
				}
			}
		});
//		priInvSuccess(csChaNotList);//测试用代码
		var conn2 = new ActiveXObject("ADODB.Connection");
		var strdsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\\SK;Exclusive=No;"
		conn2.Open(strdsn);
		var sql = "select status from cw_sk_maintable  where tzdh in(" + chaNotNos + ")";
		var objrs = conn2.Execute(sql);
		while (!objrs.EOF) {
			if (objrs.Fields(0).Value == '0') {
				break;
			}
			objrs.moveNext(); // 移到下一笔记录
		}
		if (objrs.EOF) {
			//获取发票号 start
			var querySql = "select tzdh,invoiceno from cw_sk_maintable where tzdh in("+ chaNotNos + ")"
			var ret = conn2.Execute(querySql);
			var backList = new Array();
			while(!ret.EOF){
				var notNos = "";
				var invNos = "";
				notNos = ret.Fields(0).Value;
				invNos = ret.Fields(1).value;
				backList.push(notNos +"_" + invNos);
				ret.moveNext();
			}
			//获取发票号 end
			//创建打发票信息并回写发票号
			priInvSuccess(backList);
		}else{
			alertShow("消息：正在打票,请稍候！");
		}
		objrs.Close();
		objrs = null;
		conn2.Close(); //关闭数据库链接
		conn2 = null;
	}
}

//税控发票--完成
function priInvSuccess(backList) {
    closeWaitWin();
	//获取汇款单信息以判断
	var remiIdArrayIds = $("#remiId").val();
	var ids=$("#mFrame")[0].contentWindow.$("#ids").val();
	location.href = getBasePath() + "/fm/priInvAction.action?ids=" + ids + "&remiIdArrayIds=" + remiIdArrayIds + "&backListStr=" + backList;
	parent.closeTopLeftShadow();
}

/**
 * 点击取消按钮时，设置此次进入中间库的通知单信息置为无效【修改状态为4】
 */
function canclePri(){
	if($("#printBtn").attr("disabled")){
		var csChaNotList;//封装通知单信息
		var ids = $("#mFrame")[0].contentWindow.$("#ids").val();//通知单ID串
		//获取需打印发票的通知单编号
		var chaNotNos = new Array();
		$.post(path + "/fm/getInvChaList.action", {"ids":ids}, function(result){
			if(result.exception!=undefined){
				alertShow(result.exception.message);
			}else{
				if(undefined != result.allChaNotList){
					csChaNotList = result.allChaNotList;
					$.each(csChaNotList,function(index,value){
						chaNotNos.push("'"+value.chaNotNo+"'");
					});
				}
			}
		});
		var conn = new ActiveXObject("ADODB.Connection");
		var strdsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\\SK;Exclusive=No;"
			conn.Open(strdsn);
		try {
			conn.BeginTrans();
			if(chaNotNos.length > 0){
				var sqlMain = "update cw_sk_maintable set status = '4' where tzdh in("+ chaNotNos + ") and status = '0'";
				conn.Execute(sqlMain);
				var sqlDelMain = "delete from cw_sk_maintable where tzdh in("+ chaNotNos + ") and status = '4'";
				conn.Execute(sqlDelMain);
				var sqlDetail = "delete from cw_sk_detailstable where tzdh in("+ chaNotNos + ")";
				conn.Execute(sqlDetail);
			}
			conn.CommitTrans();
			conn.Close();
			conn = null;
		} catch (e) {
			alertShow(e.message);
			conn.RollbackTrans();
		}
	}
	customCloseDialog();
	parent.closeTopLeftShadow();
}

/**
 * 假打票
 */
function playPriInv(){
    openWaitWin('请等待');
	var nowDate = new Date();
	var day = nowDate.getDay();
	var hour = nowDate.getHours();
	var min = nowDate.getMinutes();
	var sec = nowDate.getSeconds();
	var thisDay;
	var thisHour;
	var thisMin;
	var thisSec;
	if(day < 10){
		thisDay = "0" + day.toString();
	}else{
		thisDay = day.toString();
	}
	if(hour < 10){
		thisHour = "0" + hour.toString();
	}else{
		thisHour = hour.toString();
	}
	if(min < 10){
		thisMin = "0" + min.toString();
	}else{
		thisMin = min.toString();
	}
	if(sec < 10){
		thisSec = "0" + sec.toString();
	}else{
		thisSec = sec.toString();
	}
	var invNo = thisDay + thisHour + thisMin + thisSec;//获取当前年月，和发票项目写在一起写入数据库
	var csChaNotList;//封装通知单信息
	var ids = $("#mFrame")[0].contentWindow.$("#ids").val();//通知单ID串
	if(undefined != ids){
		//获取需打印发票的通知单编号
		var chaNotNos = new Array();
		$.post(path + "/fm/getInvChaList.action", {"ids":ids}, function(result){
			if(result.exception!=undefined){
			    closeWaitWin();
			    alertShow(result.exception.message);
			}else{
				if(undefined != result.allChaNotList){
					csChaNotList = result.allChaNotList;
					$.each(csChaNotList,function(index,value){
						chaNotNos.push(value.chaNotNo+"_"+invNo);
					});
					priInvSuccess(chaNotNos.toString());
					
				}
			}
		});
		
	//  setTimeout(function(){
	//		priInvSuccess(chaNotNos.toString());
	//	},500);
		
	}else{
	    closeWaitWin();
		canclePri();
	}
}

//信息的放大
function openMaxDiv(divId){
	//应收的放大
	if(divId == "chaDiv"){
		$("#payDiv").addClass("divHidden");
		$("#funDiv").addClass("divHidden");
		$("#accDiv").addClass("divHidden");
		
		$("#chaMaxDiv").addClass("divHidden");
		$("#chaMinDiv").removeClass("divHidden");
		
		$("#payTd").addClass("divHidden");
		$("#funTd").addClass("divHidden");
		$("#accTd").addClass("divHidden");
		$("#chaTd").addClass("tdWidth");
		$("#chaDiv").css("height","310px");
		$("#chaBody").css("height","251px");
		
		var minDiv = "";//$("#table1 tr:lase-child").html();
		maxDiv1 = 1;//放大
		//alert("行数:"+lineNum1);
		if(lineNum1>=0&&lineNum1<10){
			if(lineNum1>=0&&lineNum1<=3){
				for(var i=1 ;i<8;i++){
					minDiv = minDiv + htmlTable;
				}
			}else{
				for(var i=1 ;i<11-lineNum1;i++){
					minDiv = minDiv + htmlTable;
				}
			}
			$('#table1 tbody').after(minDiv);
		}
		var num = 0;
		$("#table1 tr").each(function(){
			num++;
			if(num%2 != 0){
				$(this).addClass("odd");
			}
		});
	}
	
	//欠费的放大
	if(divId == "payDiv"){
		$("#chaDiv").addClass("divHidden");
		$("#funDiv").addClass("divHidden");
		$("#accDiv").addClass("divHidden");
		
		$("#payMaxDiv").addClass("divHidden");
		$("#payMinDiv").removeClass("divHidden");
		
		$("#chaTd").addClass("divHidden");
		$("#funTd").addClass("divHidden");
		$("#accTd").addClass("divHidden");
		$("#payTd").addClass("tdWidth");
		$("#payDiv").css("height","310px");
		$("#payBody").css("height","251px");
		//alert("行数:"+lineNum2);
		var minDiv = "";
		maxDiv2 = 1;//放大
		if(lineNum2>=0&&lineNum2<10){
			if(lineNum2>=0&&lineNum2<=3){
				for(var i=1 ;i<8;i++){
					minDiv = minDiv + htmlTable;
				}
			}else{
				for(var i=1 ;i<11-lineNum2;i++){
					minDiv = minDiv + htmlTable;
				}
			}
			$('#table2 tbody').after(minDiv);
		}
		var num = 0;
		$("#table2 tr").each(function(){
			num++;
			if(num%2 != 0){
				$(this).addClass("odd");
			}
		});
	}
	
	//公积金的放大
	if(divId == "funDiv"){
		$("#chaDiv").addClass("divHidden");
		$("#payDiv").addClass("divHidden");
		$("#accDiv").addClass("divHidden");
		
		$("#funMaxDiv").addClass("divHidden");
		$("#funMinDiv").removeClass("divHidden");
		
		$("#chaTd").addClass("divHidden");
		$("#payTd").addClass("divHidden");
		$("#accTd").addClass("divHidden");
		$("#funTd").addClass("tdWidth");
		$("#funDiv").css("height","310px");
		$("#funBody").css("height","251px");
		//alert("行数:"+lineNum3);
		var minDiv = "";
		maxDiv3 = 1;//放大
		if(lineNum3>=0&&lineNum3<10){
			if(lineNum3>=0&&lineNum3<=3){
				for(var i=1 ;i<8;i++){
					minDiv = minDiv + htmlTable;
				}
			}else{
				for(var i=1 ;i<11-lineNum3;i++){
					minDiv = minDiv + htmlTable;
				}
			}
			$('#table3 tbody').after(minDiv);
		}
		var num = 0;
		$("#table3 tr").each(function(){
			num++;
			if(num%2 != 0){
				$(this).addClass("odd");
			}
		});
	}
	
	//账期的放大
	if(divId == "accDiv"){
		$("#chaDiv").addClass("divHidden");
		$("#payDiv").addClass("divHidden");
		$("#funDiv").addClass("divHidden");
		
		$("#accMaxDiv").addClass("divHidden");
		$("#accMinDiv").removeClass("divHidden");
		
		$("#chaTd").addClass("divHidden");
		$("#payTd").addClass("divHidden");
		$("#funTd").addClass("divHidden");
		$("#accDiv").css("height","310px");
		$("#accBody").css("height","251px");
		//alert("行数:"+lineNum4);
		var minDiv = "";
		maxDiv4 = 1;//放大
		if(lineNum4>=0&&lineNum4<10){
			if(lineNum4>=0&&lineNum4<=3){
				for(var i=1 ;i<8;i++){
					minDiv = minDiv + htmlTable4;
				}
			}else{
				for(var i=1 ;i<11-lineNum4;i++){
					minDiv = minDiv + htmlTable4;
				}
			}
			$('#table4 tbody').after(minDiv);
		}
		var num = 0;
		$("#table4 tr").each(function(){
			num++;
			if(num%2 != 0){
				$(this).addClass("odd");
			}
		});
	}
	
}

//信息的缩小
function openMinDiv(divId){
	//应收的缩小
	if(divId == "chaDiv"){
		$("#payDiv").removeClass("divHidden");
		$("#funDiv").removeClass("divHidden");
		$("#accDiv").removeClass("divHidden");
		
		$("#chaMaxDiv").removeClass("divHidden");
		$("#chaMinDiv").addClass("divHidden");
		
		$("#payTd").removeClass("divHidden");
		$("#funTd").removeClass("divHidden");
		$("#accTd").removeClass("divHidden");
		$("#chaTd").removeClass("tdWidth");
		$("#chaDiv").css("height","160px");
		$("#chaBody").css("height","105px");
		//如果页面数据少于等于3行 删除添加列 否则不变
		//alert("行数:"+lineNum1);
		maxDiv1 = 0;//缩小
		var deline = 0;
		var i = 0;
		if(lineNum1<=3){
			deline = 3;
		}else{
			deline = lineNum1;
		}
		$("#table1").find("tr").each(function(){
			if(i>deline){
				$(this).remove();
			}
			i++;
		});
	}
	
	//欠费的缩小
	if(divId == "payDiv"){
		$("#chaDiv").removeClass("divHidden");
		$("#funDiv").removeClass("divHidden");
		$("#accDiv").removeClass("divHidden");
		
		$("#payMaxDiv").removeClass("divHidden");
		$("#payMinDiv").addClass("divHidden");
		
		$("#chaTd").removeClass("divHidden");
		$("#funTd").removeClass("divHidden");
		$("#accTd").removeClass("divHidden");
		$("#payTd").removeClass("tdWidth");
		$("#payDiv").css("height","160px");
		$("#payBody").css("height","105px");
		//alert("行数:"+lineNum2);
		maxDiv2 = 0;//缩小
		var deline = 0;
		var i = 0;
		if(lineNum2<=3){
			deline = 3;
		}else{
			deline = lineNum2;
		}
		$("#table2").find("tr").each(function(){
			if(i>deline){
				$(this).remove();
			}
			i++;
		});
	}
	
	//公积金的缩小
	if(divId == "funDiv"){
		$("#chaDiv").removeClass("divHidden");
		$("#payDiv").removeClass("divHidden");
		$("#accDiv").removeClass("divHidden");
		
		$("#funMaxDiv").removeClass("divHidden");
		$("#funMinDiv").addClass("divHidden");
		
		$("#chaTd").removeClass("divHidden");
		$("#payTd").removeClass("divHidden");
		$("#accTd").removeClass("divHidden");
		$("#funTd").removeClass("tdWidth");
		$("#funDiv").css("height","160px");
		$("#funBody").css("height","105px");
		//alert("行数:"+lineNum3);
		maxDiv3 = 0;//缩小
		var deline = 0;
		var i = 0;
		if(lineNum3<=3){
			deline = 3;
		}else{
			deline = lineNum3;
		}
		$("#table3").find("tr").each(function(){
			if(i>deline){
				$(this).remove();
			}
			i++;
		});
	}
	
	//账期的缩小
	if(divId == "accDiv"){
		$("#chaDiv").removeClass("divHidden");
		$("#payDiv").removeClass("divHidden");
		$("#funDiv").removeClass("divHidden");
		
		$("#accMaxDiv").removeClass("divHidden");
		$("#accMinDiv").addClass("divHidden");
		
		$("#chaTd").removeClass("divHidden");
		$("#payTd").removeClass("divHidden");
		$("#funTd").removeClass("divHidden");
		$("#accDiv").css("height","160px");
		$("#accBody").css("height","105px");
		//alert("行数:"+lineNum4);
		maxDiv4 = 0;//缩小
		var deline = 0;
		var i = 0;
		if(lineNum4<=3){
			deline = 3;
		}else{
			deline = lineNum4;
		}
		$("#table4").find("tr").each(function(){
			if(i>deline){
				$(this).remove();
			}
			i++;
		});
	}
}

/**
 * 新打发票按钮
 */
function printInvNew(){
	if($("input[name='checkName_two']:checked").length == 0){
		alertShow("请选择通知单后再进行【税控发票】操作！");
	}else{
		var dose = '0';
		var showItem = '';
		//获取通知单ids通过iframe传给后台
		var ids = [];
		var borrowNum = 0;
		$("input[name='checkName_two']:checked").each(function(){
			if($(this).attr('chaTag')==2){
				dose = '1';
			}
			ids.push($(this).val());
			if(showItem == ''){
				showItem = $(this).attr('claTag');
			}
			//判断选中的通知单是否全是借票
			if(borrowInvTag == $(this).attr('invTag')){
				borrowNum++;
			}
		});
		if(borrowNum == $("input[name='checkName_two']:checked").length){
			alertShow("您所选的通知单全部为【借票】的，请选择【借票认领】操作！");
		}else{
			var notAmos = $("#openSumId").val();
			var remiIds = $("#remiId").val();//汇款单ID串
			var remiAmo = $("#remiAmo").val().replace(/,/g,"");//汇款单总金额
			var openSumId = $("#openSumId").val().replace(/,/g,"");//通知单总金额
			var notRemiSum = accSubtr(parseFloat(remiAmo).toFixed(2),parseFloat(openSumId).toFixed(2));//汇款单总金额-通知单总金额
			if(remiAmo!= null && remiAmo>0 && notRemiSum<0 ){
				alertShow("您所选汇款单总金额不够支付通知单总金额，请重新选择！");
			}else{
				var remitBalance = $("#remitBalance").val().replace(/,/g,"");//产生余额
				var remitCount = $("#remitCount").val();//汇款单张数
				if(dose == '1'){
					confirmShow("您所选通知单中包含已交通知单，是否需要继续打票？",function(){
						if($("input[name='checkName_two']:checked").length < 1){
							openDialog("shadow","DialogMsgThr");
						}else{
						    openWaitWin('请等待'); 
						    $.ajax({
		                             type:"POST",
	                                 timeout: 1000000,
	                                  url:getBasePath() + "/fm/invChaActionNewAjax.action", 
									  data:{"ids" : ids.toString()},
									  success: function(result){
										if(undefined != result.exception){
										    closeWaitWin();
											alertShow(result.exception.message);
										}else{
											closeWaitWin();
											parent.openTopLeftShadow();
											document.getElementById("mFrameNew").src = getBasePath() + "/fm/busiInvChaActionNew.action?ids=" + ids 
											+ "&message=" + notAmos + "&remiIdArrayIds=" + remiIds + "&remiTotalAmo=" + remiAmo
											+ "&remitBalance=" + remitBalance + "&remiNum=" + remitCount+ "&showItem=" + showItem+ "&borrowNum="+borrowNum;
											openDialog("shadowNew","DialogNew");
										}
									},error:function(msg){
										closeWaitWin();
			                            alertShow("服务器未返回数据,请稍后重试！");
		                            }
					           });
						}
					});
				}else{
					if($("input[name='checkName_two']:checked").length < 1){
						openDialog("shadow","DialogMsgThr");
					}else{
					    openWaitWin('请等待'); 
					      $.ajax({
		                             type:"POST",
	                                 timeout: 1000000,
	                                  url:getBasePath() + "/fm/invChaActionNewAjax.action", 
									  data:{"ids" : ids.toString()},
									  success: function(result){
										if(undefined != result.exception){
										    closeWaitWin();
										    alertShow(result.exception.message);
										}else{
										    closeWaitWin();
											parent.openTopLeftShadow();
											document.getElementById("mFrameNew").src = getBasePath() + "/fm/busiInvChaActionNew.action?ids=" + ids 
											+ "&message=" + notAmos + "&remiIdArrayIds=" + remiIds + "&remiTotalAmo=" + remiAmo
											+ "&remitBalance=" + remitBalance + "&remiNum=" + remitCount+ "&showItem=" + showItem + "&borrowNum="+borrowNum;
											openDialog("shadowNew","DialogNew");
										}
									},error:function(msg){
										closeWaitWin();
										alertShow("服务器未返回数据,请稍后重试！");
		                            }
					           });
					}
				}
			}
			}
	}
}

/**
 * 借票认领操作
 */
function remiClaim(){
	//获取通知单ids通过iframe传给后台
	var ids = [];
	$("input[name='checkName_two']:checked").each(function(){
		ids.push($(this).val());
	});
	if(ids.join(",")==''){
		alertShow("请选择状态为借票的通知单！");
		return true;
	}
	if(allAmoRm >= sum){
		confirmShow("您确定认领吗？",function(){
			$.post(getBasePath() + "/fm/authenticateUpdateOth.action",{"idNotice":ids.join(","),"idRemi":remiIdArrayIds},function(result){
				if(result.exception==undefined){
					alertShow("认领成功！",function(){
						$("#hiddenSelForm").submit();
					});	  
				}else{
					alertError(result);
				}
			});
		});
	}else{
		alertShow("汇款单金额不能小于通知单金额！");
	}
}
/**
 * 返回签收页面
 */
function returnRemiPub(){
	openDialog('shadowReturn','DialogReturn');
}

/**
 * 标记财务不能处理
 */
function updateRemiFmNo(){
	if(null != remiIdArrayIds && remiIdArrayIds != ""){
		$.post(
		    getBasePath() + "/fm/updateChaRemiNoFmWork.action",
		    {"remiIds" : remiIdArrayIds},
		    function(result){
		    	if(undefined != result.exception){
		    		closeWaitWin();
		    		alertShow(result.exception.message);
		    	}else{
		    		$("#hiddenSelForm").submit();
		    	}
		    }
		);
	}else{
		alertShow("提示：汇款单信息丢失，请重新操作！");
	}
}

/**
 * @param table
 * @param index
 */
function thisTableHeadOver(table, index){
	table.parent().find("div[name=overHeadDiv]").remove();
	var parentDiv = table.parent();
	//外部div高度
	var parHeight = parentDiv==null||parentDiv.attr("tagName")=="BODY"||parentDiv.attr("style")==null||(parentDiv.attr("style").indexOf("HEIGHT")<0&&parentDiv.attr("style").indexOf("height")<0) ? 0 : parseInt(parentDiv.css("height")||parentDiv.attr("height"));

	//tr总高度
	var trHeight=0;
	$.each(table.find("tr"),function(i,n){
		trHeight+=$(n).height();
	});
	var leftWidth = 0;
	if(index == 1){
		leftWidth = 10;
	}else if(index == 2){
		leftWidth = parentDiv.attr("offsetWidth") + 5;
	}else if(index == 3){
		leftWidth = (parentDiv.attr("offsetWidth") + 5)*2;
	}else if(index == 4){
		leftWidth = 6;
	}else{
		leftWidth = 0;
	}
	if(parHeight<trHeight){
		var ie7 = navigator.appName == "Microsoft Internet Explorer"&&document.documentMode==7;
		var newTab = $("<table id='newTab_" + table.attr("id") + "'></table>").css("position","relative");

		//如果父节点为body，则套一层div
		if(parentDiv==null||parentDiv.attr("tagName")=="BODY")
			parentDiv =$("<div/>");
		parentDiv.css("height",parHeight==0 ?trHeight-23:parHeight).css("overflow-y","auto");
		//绑定左移滚动条方法
		parentDiv.scroll(function(){
			var div = $(this);
			newTab.css("margin-left",(div.scrollLeft()-div.scrollLeft()*2));
		});
		
		//开始动态构建head
		var newBody =table.find("tr:eq(0)").clone(true);
		//如果需要overHead和drag兼容的话，这里要删掉原来table上的div，以固定表头的来做
		if(table.attr("drag"))
			table.find("div[dragDiv=true]").remove(); 
		var trs = table.find("tr:eq(0) th");
		$.each(trs,function(i,n){
			newBody.find("th:eq("+i+")").width($(n).css("width")).removeAttr("id").removeAttr("name");
		});
		
		var bodyScrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
		var top = parseInt(parentDiv.offset().top);
		var tops = (top-bodyScrollTop<0 ? 0 : top-bodyScrollTop);
		var ftop = parseInt(parentDiv.offset().top)==0 ?trHeight-parHeight-23:parseInt(parentDiv.offset().top);//div的上偏移
		
		newTab.append($("<thead/>"));
		newTab.find("thead").append(newBody);
		
		var outDivWidth=parentDiv.attr("offsetWidth")-16;
		if(parentDiv.attr("style")!=null&&parentDiv.attr("style").indexOf("scroll")>0)//如果滚动条是强制显示的，就不需要减16
			outDivWidth=parentDiv.attr("offsetWidth");
		
		var outDiv = $("<div/>").append(newTab)
		.attr("name","overHeadDiv_" + table.attr("id"))
		.css("overflow","hidden")
		.css("position","fixed")
		.css("width",outDivWidth)
		.css("top",tops)
		.css("left", parentDiv.offset().left) //左边距
		.attr("ftop",ftop);//上边距
		if(table.attr("drag")){
			outDiv.css("z-index","1");
		}
		//将div放在父级div中
		parentDiv.prepend(outDiv);
		//设置放固定表头的table的宽度为原来table的最大宽度 (包含滚动条的)
		newTab.css("width",table.attr("offsetWidth"));
		
		$(window).scroll(function(){
			var bodyScrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
			var top =parseInt(outDiv.attr("ftop"));
			var topsa = (top-bodyScrollTop<0 ? 0 : top-bodyScrollTop);
			$("div[name='overHeadDiv_" + table.attr("id") + "']").css("top",topsa+"px");//暂时这样搜索全部的div进行修改
			
			var scrollLeft = document.documentElement.scrollLeft || window.pageXOffset || document.body.scrollLeft;
			$("div[name='overHeadDiv_" + table.attr("id") + "']").css("left","-"+scrollLeft+"px");//暂时这样搜索全部的div进行修改
		});
	}
}
//重置自定义方法
function resetItems(){
	$("#custName_input_dep").val("");
	$("#custName_input_rep").val("");
	$("#custName_input_name").val("");
	$("#chaNotNoId").val("");
	$("#custNoId").val("");
}

function showNotice(){
	console.log('showNotice');
    var ck = $("#ajaxTable1_table").find(":checkbox[name='checkNameAccu']:checked");
    if(ck.size() != 1){
		alertShow("请选择一条数据");
		return;
	}else{
		var custAccuId = ck.attr('custAccuId');
		var busiYM = ck.attr('busiYM');
		var custId = ck.attr('custId');
    	document.getElementById("detFrameNotice").src = 
    		getBasePath() + "/fm/findByCsChaNotEntityByCustAccuId.action?custAccuId="
    		 +custAccuId+"&formCsChaNot.busiYm="+busiYM+"&formCsChaNot.busiCustId="+custId;
		openDialog('showData2', 'dialogShowData2');
   }
}